package com.wontube.client.modle.vo;

import java.io.Serializable;

/**
 * @author yuechao
 * 
 *         分页支持
 */
public class PagenateInfo implements Serializable {
	private static final long serialVersionUID = 1L;
	
	public PagenateInfo() {		
		this(1, 10);
	}
	
	public PagenateInfo(int pageNo, int pageSize){
		this.pageNo = pageNo;
		this.pageSize = pageSize;
	}
	
	private int pageNo;
	private int pageSize;

	/**
	 * 获取当前页码
	 * 
	 * @return
	 */
	public int getPageNo() {
		return this.pageNo;
	}

	/**
	 * 设置当前页码
	 * 
	 * @param pageNo
	 */
	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	/**
	 * 获取每页的数量
	 * 
	 * @return
	 */
	public int getPageSize() {
		return this.pageSize;
	}

	/**
	 * 设置每面的数量
	 * 
	 * @param pageSize
	 */
	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	/**
	 * 开始页面，从1开始计数
	 * 
	 * @return
	 */
	public int getStart() {
		return (this.pageNo - 1) * this.pageSize + 1;
	}

	public int getOffset() {
		return this.getStart() - 1;
	}

	public int getLimit() {
		return this.pageSize;
	}

	/**
	 * 结束页面，从1开始计数
	 * 
	 * @return
	 */
	public int getEnd() {
		int start = this.getStart();
		return start + this.pageSize - 1;
	}
	
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + this.pageNo;
		result = prime * result + this.pageSize;
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (getClass() != obj.getClass()) {
			return false;
		}
		PagenateInfo other = (PagenateInfo) obj;
		if (pageNo != other.pageNo) {
			return false;
		}
		if (pageSize != other.pageSize) {
			return false;
		}
		return true;
	}
}
